Variables:
Risk Age Sex Country
library(data.table)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
data.table 1.14.8 using 1 threads (see ?getDTthreads). Latest news: r-datatable.com
**********
This installation of data.table has not detected OpenMP support. It should still work but in single-threaded mode.
This is a Mac. Please read https://mac.r-project.org/openmp/. Please engage with Apple and ask them for support. Check r-datatable.com for updates, and our Mac instructions here: https://github.com/Rdatatable/data.table/wiki/Installation. After several years of many reports of installation problems on Mac, it's time to gingerly point out that there have been no similar problems on Windows or Linux.
**********
Attaching package: ‘data.table’
The following objects are masked from ‘package:dplyr’:
between, first, last
library(tidyr)
library(maps)
library(haven)
library(ggplot2)
library(dplyr)
#read the data (Wave 5)
# Data of Wave 5
WV5_data <- readRDS("/Users/cristinacandido/Documents/Github/risk_wvs/data/WVS/F00007944-WV5_Data_R_v20180912.rds")
# Convert WV5_data-object in data.frame
WV5_data_df <- as.data.frame(WV5_data)
# show first five columns
WV5_data_df
# Read countrynames data from the CSV file
countrynames <- read.csv("/Users/cristinacandido/Documents/Github/risk_wvs/data/WVS/countrynames.txt", header = FALSE, as.is = TRUE)
colnames(countrynames) <- c("code", "name")
# Assuming WV5_data has a column named country_code
WV5_data$country <- countrynames$name[match(WV5_data$country_code, countrynames$code)]
# Check the frequency of each country in the new column
table(WV5_data$country)
Andorra Argentina Australia Brazil
1003 1002 1421 1500
Bulgaria Burkina Faso Canada Chile
1001 1534 2164 1000
China Colombia Cyprus (G) Egypt
1991 3025 1050 3051
Ethiopia Finland France Georgia
1500 1014 1001 1500
Germany Ghana Great Britain Guatemala
2064 1534 1041 1000
Hong Kong Hungary India Indonesia
1252 1007 2001 2015
Iran Iraq Italy Japan
2667 2701 1012 1096
Jordan Malaysia Mali Mexico
1200 1201 1534 1560
Moldova Morocco Netherlands New Zealand
1046 1200 1050 954
Norway Peru Poland Romania
1025 1500 1000 1776
Russia Rwanda Slovenia South Africa
2033 1507 1037 2988
South Korea Spain Sweden Switzerland
1200 1200 1003 1241
Taiwan Thailand Trinidad and Tobago Turkey
1227 1534 1002 1346
Ukraine United States Uruguay Viet Nam
1000 1249 1000 1495
Zambia
1500
# Display the updated WV5_data
print(WV5_data)
#Read Dataset (Wave 6)
WV6_data <- load("/Users/cristinacandido/Documents/Github/risk_wvs/data/WVS/WV6_Data_R_v20201117.rdata")
WV6_data <- WV6_Data_R_v20201117
print(WV6_data)
#rename variables
#decode daraset (Wave 6)
countrynames = read.csv("/Users/cristinacandido/Documents/Github/risk_wvs/data/WVS/countrynames.txt", header=FALSE,as.is=TRUE)
colnames(countrynames) = c("code", "name")
WV6_data$country = countrynames$name [match(WV6_data$country_code, countrynames$code)]
table(WV6_data$country)
Algeria Argentina Armenia Australia
1200 1030 1100 1477
Azerbaijan Belarus Brazil Chile
1002 1535 1486 1000
China Colombia Cyprus (G) Ecuador
2300 1512 1000 1202
Egypt Estonia Georgia Germany
1523 1533 1202 2046
Ghana Haiti Hong Kong India
1552 1996 1000 4078
Iraq Japan Jordan Kazakhstan
1200 2443 1200 1500
Kuwait Kyrgyzstan Lebanon Libya
1303 1500 1200 2131
Malaysia Mexico Morocco Netherlands
1300 2000 1200 1902
New Zealand Nigeria Pakistan Palestine
841 1759 1200 1000
Peru Philippines Poland Qatar
1210 1200 966 1060
Romania Russia Rwanda Singapore
1503 2500 1527 1972
Slovenia South Africa South Korea Spain
1069 3531 1200 1189
Sweden Taiwan Thailand Trinidad and Tobago
1206 1238 1200 999
Tunisia Turkey Ukraine United States
1205 1605 1500 2232
Uruguay Uzbekistan Yemen Zimbabwe
1000 1500 1000 1500
WV6_data
#combine the 2 dataset (Wave 6 + Wave 5)
WV5_data
WV6_data
WVS_data = rbind(WV5_data, WV6_data)
WVS_data
NA
NA
NA
NA
NA
#exclusion of participants and omission of missing data (na)
#World map
world_map <- map_data("world")
recorded_countries <- unique(WVS_data$country)
world_map$recorded <- ifelse(world_map$region %in% recorded_countries, "Recorded", "Not Recorded")
ggplot(world_map, aes(x = long, y = lat, group = group, fill = recorded)) +
geom_polygon(color = "white") +
scale_fill_manual(values = c("Recorded" = "red", "Not Recorded" = "lightgrey"), guide = "none") +
theme_void() +
labs(title = "WVS", fill = "Status") +
theme(legend.position = "none", plot.title = element_text(hjust = 0.5))
# Load the dplyr package
library(dplyr)
# Assuming the data frame is called 'data' and the column containing the country information is called 'country'
country_counts <- WVS_data %>%
count(country)
# Print the result
print(country_counts)
NA
# read in file that contains hardship indicators manually collected from CIA factbook, WHO, and World Bank
# (see Supplemental Materials for URL sources)
countryfacts = read.csv("/Users/cristinacandido/Documents/Github/risk_wvs/data/WVS/countryfacts_selection.csv", as.is = TRUE, header = TRUE)
# Create a vector of labels with the same length as the number of columns in 'countryfacts'
labels <- c("code","country","codeWVS","Homicide","GDP","InfMort","LifeExp","GINI","GenderPEdu","code2")
# Print the result
print(countryfacts)
# Load the dplyr package if not already loaded
if (!require(dplyr)) {
install.packages("dplyr")
library(dplyr)
}
# Create the 'hardship' column in the 'countryfacts' data frame
countryfacts <- countryfacts %>%
mutate(hardship = (homiciderate + gdp + infantmortality + lifeexpectancy + gini + femalemale_primedu) / 6)
countryfacts
# View the distribution of the 'hardship_index' column for each country
hardship_index_distribution <- countryfacts %>%
group_by(label) %>%
summarize(
mean = mean(hardship, na.rm = TRUE),
median = median(hardship, na.rm = TRUE),
sd = sd(hardship, na.rm = TRUE),
min = min(hardship, na.rm = TRUE),
max = max(hardship, na.rm = TRUE),
n = sum(!is.na(hardship))
)
# Print the result
print(hardship_index_distribution)
#table with female percentage, mean age, mean risk taking per countries (summary of the countries)
library(dplyr)
table_data_WVS <- WVS_data %>%
group_by(country) %>%
summarise(
n = n(),
female_percentage = mean(gender == 1) * 100,
mean_age = mean(age, na.rm = TRUE),
age_range = paste(min(age, na.rm = TRUE), "-", max(age, na.rm = TRUE)),
mean_risktaking = mean(Z_score_risktaking, na.rm = TRUE)
)
table_data_WVS
#graph across countries: risk taking vs age vs gender (Z-score for age and risk taking)
# Risk vs age with color-coded gender per Country
# Risk vs age with color-coded gender per Country
# Skalierung des Z-Scores für das Alter anpassen
WVS_data$z_score_age_scaled <- 15 * WVS_data$z_score_age + 42
ggplot(WVS_data, aes(z_score_age_scaled, Z_score_risktaking, color = as.factor(gender))) +
geom_point(position = position_jitter(width = 0.1, height = 0.1), size = 0.1) +
geom_smooth(method = "lm") +
geom_vline(xintercept = 42, linetype = "dashed", color = "black", size = 1) +
scale_color_manual(values = c("blue", "red"), labels = c("Male", "Female")) +
labs(color = "Gender") +
xlab("Age") +
ylab("Risk Taking") +
scale_x_continuous(breaks = seq(0, 100, by = 15), limits = c(0, 100)) +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
Please use `linewidth` instead.
WVS_data
NA
NA
NA
NA
NA
NA
NA
NA
NA
#regression table (risk taking and age -> Z-score)
regression_results_WVS <- WVS_data %>%
group_by(country) %>%
do(model = lm(Z_score_risktaking ~ scale(age) + gender, data = .)) %>%
summarize(
country = first(country),
intercept = coef(summary(model))[1, 1],
slope_age = coef(summary(model))[2, 1],
slope_gender = coef(summary(model))[3, 1]
)
regression_results_WVS
NA
NA
gps_data <- haven::read_dta("/Users/cristinacandido/Documents/Github/risk_wvs/data/individual_new.dta")
gps_data
# Clean the data by removing records with missing values
gps_data <- gps_data %>%
drop_na(country, isocode, risktaking, gender, age)
# Display the cleaned data
gps_data
#select only the variables of interest
gps_data <- gps_data %>%
dplyr::select(country, isocode, ison, risktaking, gender, age)
gps_data
#Z-score for age
gps_data <- gps_data %>%
group_by(country) %>%
mutate(z_score_age = scale(age))
# Display the new column with Z-Scores per Country
gps_data
#table intercept and slope
regression_results_gps <- gps_data %>%
group_by(country) %>%
do(model = lm(risktaking ~ z_score_age + gender, data = .)) %>%
summarize(
country = first(country),
intercept = coef(summary(model))[1, 1],
slope_age = coef(summary(model))[2, 1],
slope_gender = coef(summary(model))[3, 1]
)
regression_results_gps
common_countries <- intersect(WVS_data$country, gps_data$country)
selected_countries <- c("Argentina", "Australia", "Brazil", "Canada", "Chile", "China", "Egypt", "Finland", "France", "Georgia",
"Germany", "Ghana", "Hungary", "India", "Indonesia", "Iran", "Japan", "Jordan", "Mexico", "Moldova",
"Morocco", "Netherlands", "Peru", "Poland", "Romania", "Russia", "Rwanda", "South Africa", "South Korea",
"Spain", "Sweden", "Switzerland", "Thailand", "Turkey", "Ukraine", "United States", "Algeria", "Colombia",
"Estonia", "Haiti", "Iraq", "Kazakhstan", "Nigeria", "Pakistan", "Philippines", "Zimbabwe", "United Kingdom")
# Filter the original dataset
new_WVS <- WVS_data[WVS_data$country %in% selected_countries, ]
# View the new dataset
new_WVS
NA
NA
selected_countries <- c("Argentina", "Australia", "Brazil", "Canada", "Chile", "China", "Egypt", "Finland", "France", "Georgia",
"Germany", "Ghana", "Hungary", "India", "Indonesia", "Iran", "Japan", "Jordan", "Mexico", "Moldova",
"Morocco", "Netherlands", "Peru", "Poland", "Romania", "Russia", "Rwanda", "South Africa", "South Korea",
"Spain", "Sweden", "Switzerland", "Thailand", "Turkey", "Ukraine", "United States", "Algeria", "Colombia",
"Estonia", "Haiti", "Iraq", "Kazakhstan", "Nigeria", "Pakistan", "Philippines", "Zimbabwe", "United Kingdom")
# Filter the original dataset
new_gps <- gps_data[gps_data$country %in% selected_countries, ]
# View the new dataset
new_gps
NA
regression_results_WVS_new <- new_WVS %>%
group_by(country) %>%
do(model = lm(Z_score_risktaking ~ scale(age) + gender, data = .)) %>%
summarize(
country = first(country),
intercept_WVS = coef(summary(model))[1, 1],
slope_age_WVS = coef(summary(model))[2, 1],
slope_gender_WVS = coef(summary(model))[3, 1]
)
regression_results_WVS_new
NA
regression_results_gps_new <- new_gps %>%
group_by(country) %>%
do(model = lm(risktaking ~ scale(age) + gender, data = .)) %>%
summarize(
country = first(country),
intercept_gps = coef(summary(model))[1, 1],
slope_age_gps = coef(summary(model))[2, 1],
slope_gender_gps = coef(summary(model))[3, 1]
)
regression_results_gps_new
NA
library(readxl)
library(dplyr) # Don't forget to load the dplyr package
regression_results_gps_new
regression_results_WVS_new
# Assuming "country" is the common column
merged_results <- merge(regression_results_gps_new, regression_results_WVS_new, by = "country", all = TRUE)
# Read data from the Excel file
new_data <- read_excel("/Users/cristinacandido/Documents/Github/risk_wvs/data/Hardship_complete.xlsx")
# Now you can work with the 'new_data' object
print(new_data)
# Perform the left_join operation
new_data <- left_join(merged_results, new_data, by = "country")
# Select specific columns
new_data <- new_data %>%
dplyr::select(country, intercept_gps, slope_age_gps, slope_gender_gps, intercept_WVS, slope_age_WVS, slope_gender_WVS, isocode)
# Print the final data
print(new_data)
hardship_index <- read_excel("/Users/cristinacandido/Documents/Github/risk_wvs/data/Hardship_complete.xlsx")
print(hardship_index)
hardship_data_complete <- left_join(regression_results_WVS, hardship_index, by = "country")
hardship_data_complete
NA
NA
NA
hardship_data_complete$mean_homicide=log(hardship_data_complete$mean_homicide)
hardship_data_complete$gdp=log(hardship_data_complete$gdp)
hardship_data_complete$Infant_mortality=log(hardship_data_complete$Infant_mortality)
hardship_data_complete$life_expect=log(hardship_data_complete$life_expect)
hardship_data_complete$gini_income=log(hardship_data_complete$gini_income)
# changing variables into the same direction
# Reverse Codierung
hardship_data_complete$mean_homicide=scale(hardship_data_complete$mean_homicide)
hardship_data_complete$gdp=scale(-hardship_data_complete$gdp)
hardship_data_complete$Infant_mortality=scale(hardship_data_complete$Infant_mortality)
hardship_data_complete$life_expect=scale(-hardship_data_complete$life_expect)
hardship_data_complete$gini_income=scale(hardship_data_complete$gini_income)
hardship_data_complete
hardship_data_complete$hardship=(hardship_data_complete$mean_homicide+hardship_data_complete$gdp+hardship_data_complete$gini_income+hardship_data_complete$life_expect+hardship_data_complete$Infant_mortality)/5
hardship_data_complete
NA
# Plotting comparing interecepts
ggplot(new_data, aes(x = intercept_gps, y = intercept_WVS, label = isocode)) +
geom_point(size = 1.5) +
geom_text(aes(label = isocode), vjust = -0.5, hjust = -0.5) +
geom_smooth(method = "lm", se = FALSE, linetype = "dashed") +
labs(title = "Comparison of Intercept Values",
x = "Intercept_gps",
y = "Intercept_WVS") +
theme_minimal() +
xlim(c(0, 1.2)) +
ylim(c(0, 1.2)) +
coord_fixed()
# Assuming you have a data frame named 'new_data' with columns 'intercept_gps', 'intercept_WVS', and 'isocode'
# Install and load the necessary packages
library(ggplot2)
library(ggrepel)
library(wordcloud)
Loading required package: RColorBrewer
# Assuming you have a data frame named 'new_data' with columns 'intercept_gps', 'intercept_WVS', and 'isocode'
# Scatter plot with labels
library(ggplot2)
library(ggrepel)
# Assuming you have a data frame named 'new_data' with columns 'intercept_gps', 'intercept_WVS', and 'isocode'
ggplot(new_data, aes(x = intercept_gps, y = intercept_WVS, label = isocode)) +
geom_point(size = 3) +
geom_text_repel(
aes(label = isocode),
box.padding = 0.5,
point.padding = 0.1,
force = 5
) +
geom_smooth(method = "lm", se = FALSE, linetype = "dashed") +
labs(x = "Intercept Global Preference Study",
y = "Intercept World Value Survey") +
theme_minimal() +
xlim(c(0, 1.07)) +
ylim(c(0, 1.07)) +
coord_fixed()
# Annotate with word cloud
wordcloud(words = new_data$isocode, freq = rep(1, nrow(new_data)), scale = c(2, 0.5))
# Annotate with word cloud
wordcloud(words = new_data$isocode, freq = rep(1, nrow(new_data)), scale = c(2, 0.5))
# Assuming merged_results has columns intercept_gps and intercept_WVS
model <- lm(intercept_WVS ~ intercept_gps, data = merged_results)
# View the summary of the regression model
summary(model)
Call:
lm(formula = intercept_WVS ~ intercept_gps, data = merged_results)
Residuals:
Min 1Q Median 3Q Max
-0.65390 -0.13269 -0.00167 0.15938 0.68089
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.28224 0.04289 6.580 4.28e-08 ***
intercept_gps 0.47492 0.13919 3.412 0.00137 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.2735 on 45 degrees of freedom
Multiple R-squared: 0.2055, Adjusted R-squared: 0.1879
F-statistic: 11.64 on 1 and 45 DF, p-value: 0.001373
# Calculate the correlation
correlation <- cor(merged_results$intercept_gps, merged_results$intercept_WVS)
# Print the correlation coefficient
print(correlation)
[1] 0.4533552
library(ggplot2)
# Plotting using ggplot2
ggplot(new_data, aes(x = slope_age_gps, y = slope_age_WVS, label = isocode)) +
geom_point(size = 3) +
geom_text_repel(
aes(label = isocode),
box.padding = 0.5,
point.padding = 0.1,
force = 5
) +
geom_smooth(method = "lm", se = FALSE, linetype = "dashed") +
labs(x = "Effect of Age on Risk Taking Global Preference Study",
y = "Effect of Age on Risk Taking World Value Survey") +
theme_minimal() +
xlim(-0.5, 0) +
ylim(c(-0.5, 0)) +
coord_fixed()
new_data
correlation <- cor(new_data$slope_age_gps, new_data$slope_age_WVS)
# Print the correlation coefficient
print(correlation)
[1] 0.4202296
# Plotting using ggplot2
ggplot(new_data, aes(x = slope_gender_gps, y = slope_gender_WVS, label = isocode)) +
geom_point(size = 3) +
geom_text_repel(
aes(label = isocode),
box.padding = 0.5,
point.padding = 0.1,
force = 5
) +
geom_smooth(method = "lm", se = FALSE, linetype = "dashed") +
labs(x = "Effect of Gender on Risk Taking Global Preference Study",
y = "Effect of Gender on Risk Taking World Value Survey") +
theme_minimal() +
xlim(-0.6, 0.12) +
ylim(c(-0.6, 0.12)) +
coord_fixed()
new_data
correlation <- cor(new_data$slope_gender_gps, new_data$slope_gender_WVS)
# Print the correlation coefficient
print(correlation)
[1] 0.3050746
#hardship for WVS
library(readxl)
hardship_values <- read_excel("/Users/cristinacandido/Documents/Github/risk_wvs/data/hardship_complete.xlsx") # Read data from the Excel file
labels <- c("country", "code", "gdp", "gini", "Infant_mortality", "life_expect", "hardship")
print(hardship_values)
# Assuming hardship_data_complete is your data frame with the mentioned columns
# Replace the column names as per your actual column names
# Z-standardize specific columns
hardship_values$gdp <- scale(hardship_values$gdp)
hardship_values$gini_income <- scale(hardship_values$gini_income)
hardship_values$Infant_mortality <- scale(hardship_values$Infant_mortality)
hardship_values$life_expect <- scale(hardship_values$life_expect)
hardship_values$mean_homicide <- scale(hardship_values$mean_homicide)
hardship_values
hardship_values <- hardship_values%>%
mutate(hardship = (mean_homicide + gdp + Infant_mortality + life_expect + gini_income) / 5)
hardship_values
hardship_data_complete <- left_join(regression_results_WVS, hardship_values, by = "country")
hardship_data_complete
<!-- rnb-text-end -->
<!-- rnb-chunk-begin -->
<!-- rnb-chunk-end -->
<!-- rnb-text-begin -->
<!-- rnb-text-end -->
<!-- rnb-chunk-begin -->
<!-- rnb-chunk-end -->
<!-- rnb-chunk-begin -->
<!-- rnb-chunk-end -->
<!-- rnb-chunk-begin -->
<!-- rnb-source-begin eyJkYXRhIjoiYGBgclxubGlicmFyeShnZ3JlcGVsKVxubGlicmFyeShnZ3Bsb3QyKVxuI0ZvciBXVlNcbmdncGxvdChoYXJkc2hpcF9kYXRhX2NvbXBsZXRlLCBhZXMoeCA9IGhhcmRzaGlwLCB5ID0gaW50ZXJjZXB0LCBsYWJlbCA9IGlzb2NvZGUpKSArXG4gIGdlb21fcG9pbnQoc2l6ZSA9IDMpICtcbiAgZ2VvbV90ZXh0X3JlcGVsKFxuICAgIGFlcyhsYWJlbCA9IGlzb2NvZGUpLFxuICAgIGJveC5wYWRkaW5nID0gMC41LFxuICAgIHBvaW50LnBhZGRpbmcgPSAwLjEsXG4gICAgZm9yY2UgPSA1XG4gICkgK1xuICBnZW9tX3Ntb290aChtZXRob2QgPSBcImxtXCIsIHNlID0gRkFMU0UsIGxpbmV0eXBlID0gXCJkYXNoZWRcIikgK1xuICBsYWJzKHggPSBcIkhhcmRzaGlwXCIsXG4gICAgICAgeSA9IFwiUmlzayBUYWtpbmdcIikgK1xuICB0aGVtZV9taW5pbWFsKCkgK1xuICB4bGltKC0yLCAyKSArXG4gIHlsaW0oLTAuNiwgMSkgK1xuICBjb29yZF9maXhlZChyYXRpbyA9IDIuNSlcbmBgYCJ9 -->
```r
library(ggrepel)
library(ggplot2)
#For WVS
ggplot(hardship_data_complete, aes(x = hardship, y = intercept, label = isocode)) +
geom_point(size = 3) +
geom_text_repel(
aes(label = isocode),
box.padding = 0.5,
point.padding = 0.1,
force = 5
) +
geom_smooth(method = "lm", se = FALSE, linetype = "dashed") +
labs(x = "Hardship",
y = "Risk Taking") +
theme_minimal() +
xlim(-2, 2) +
ylim(-0.6, 1) +
coord_fixed(ratio = 2.5)
<!-- rnb-text-end -->
<!-- rnb-chunk-begin -->
<!-- rnb-source-begin eyJkYXRhIjoiYGBgclxubGlicmFyeShnZ3JlcGVsKVxuXG5cbmxpYnJhcnkoZ2dyZXBlbClcbiNGb3IgV1ZTXG5nZ3Bsb3QoaGFyZHNoaXBfZGF0YV9jb21wbGV0ZSwgYWVzKHggPSBoYXJkc2hpcCwgeSA9IHNsb3BlX2FnZSwgbGFiZWwgPSBpc29jb2RlKSkgK1xuICBnZW9tX3BvaW50KHNpemUgPSAzKSArXG4gIGdlb21fdGV4dF9yZXBlbChcbiAgICBhZXMobGFiZWwgPSBpc29jb2RlKSxcbiAgICBib3gucGFkZGluZyA9IDAuNSxcbiAgICBwb2ludC5wYWRkaW5nID0gMC4xLFxuICAgIGZvcmNlID0gNVxuICApICtcbiAgZ2VvbV9zbW9vdGgobWV0aG9kID0gXCJsbVwiLCBzZSA9IEZBTFNFLCBsaW5ldHlwZSA9IFwiZGFzaGVkXCIpICtcbiAgbGFicyh4ID0gXCJIYXJkc2hpcFwiLFxuICAgICAgIHkgPSBcIkFnZSBFZmZlY3RcIikgK1xuICB0aGVtZV9taW5pbWFsKCkgK1xuICAgeGxpbSgtMiwgMikgK1xuICBjb29yZF9maXhlZChyYXRpbyA9IDgpXG4gXG5cblxuYGBgIn0= -->
```r
library(ggrepel)
library(ggrepel)
#For WVS
ggplot(hardship_data_complete, aes(x = hardship, y = slope_age, label = isocode)) +
geom_point(size = 3) +
geom_text_repel(
aes(label = isocode),
box.padding = 0.5,
point.padding = 0.1,
force = 5
) +
geom_smooth(method = "lm", se = FALSE, linetype = "dashed") +
labs(x = "Hardship",
y = "Age Effect") +
theme_minimal() +
xlim(-2, 2) +
coord_fixed(ratio = 8)
library(ggrepel)
ggplot(hardship_data_complete, aes(x = hardship, y = intercept, label = isocode)) +
geom_point(size = 3) +
geom_text_repel(
aes(label = isocode),
box.padding = 0.5,
point.padding = 0.1,
force = 5
) +
geom_smooth(method = "lm", se = FALSE, linetype = "dashed") +
labs(x = "Hardship",
y = "Risk Taking") +
theme_minimal() +
coord_fixed()
# Output for linear model for hardship & risktaking
# Lineares Modell für den ersten Fall
model_intercept <- lm(hardship ~ intercept, data = hardship_data_complete)
# Zusammenfassung des Modells
summary_intercept <- summary(model_intercept)
# Zeige die vollständige Zusammenfassung an
print(summary_intercept)
# Correlation Hardship und Risk Taking
# Entferne Zeilen mit fehlenden Werten in den relevanten Spalten
# Berechne die Korrelation erneut
correlation <- cor(hardship_data_complete$hardship, hardship_data_complete$intercept)
# Zeige die Korrelation an
print(paste("Correlation Hardship und Risk Taking:", correlation))
# Output for linear model for hardship & risktaking
# Lineares Modell für den ersten Fall
model_intercept <- lm(hardship ~ slope_age, data = hardship_data_complete)
# Zusammenfassung des Modells
summary_intercept <- summary(model_intercept)
# Zeige die vollständige Zusammenfassung an
print(summary_intercept)
# Correlation Hardship und Risk Taking
# Entferne Zeilen mit fehlenden Werten in den relevanten Spalten
# Berechne die Korrelation erneut
correlation <- cor(hardship_data_complete$hardship, hardship_data_complete$slope_age)
# Zeige die Korrelation an
print(paste("Correlation Hardship und Risk Taking:", correlation))
# Output for linear model for hardship & risktaking
# Lineares Modell für den ersten Fall
model_intercept <- lm(hardship ~ slope_gender, data = hardship_data_complete)
# Zusammenfassung des Modells
summary_intercept <- summary(model_intercept)
# Zeige die vollständige Zusammenfassung an
print(summary_intercept)
# Correlation Hardship und Risk Taking
# Entferne Zeilen mit fehlenden Werten in den relevanten Spalten
# Berechne die Korrelation erneut
correlation <- cor(hardship_data_complete$hardship, hardship_data_complete$slope_gender)
# Zeige die Korrelation an
print(paste("Correlation Hardship und Risk Taking:", correlation))
WVS_data
# Lineares Modell für Risk Taking vs. Age
model_risk_age <- lm(Z_score_risktaking ~ z_score_age + factor(gender), data = WVS_data)
# Zusammenfassung des Modells
summary_risk_age <- summary(model_risk_age)
# Zeige die vollständige Zusammenfassung an
print(summary_risk_age)
# Berechne die Korrelation erneut
correlation <- cor(WVS_data$z_score_age, WVS_data$Z_score_risktaking, WVS_data$gender)
# Zeige die Korrelation an
print(paste("Correlation Hardship und Risk Taking:", correlation))
new_data
# Lineares Modell für Risk Taking vs. Age
model <- lm(slope_gender_gps ~ slope_gender_WVS, data = new_data)
# Zusammenfassung des Modells
summary_model <- summary(model)
# Zeige die vollständige Zusammenfassung an
print(summary_model)
# Berechne die Korrelation erneut
correlation <- cor(new_data$slope_age_gps, new_data$slope_age_WVS)
# Zeige die Korrelation an
print(paste("Correlation Hardship und Risk Taking:", correlation))
library(ggrepel)
library(ggrepel)
ggplot(hardship_data_complete, aes(x = hardship, y = slope_gender, label = isocode)) +
geom_point(size = 3) +
geom_text_repel(
aes(label = isocode),
box.padding = 0.5,
point.padding = 0.1,
force = 5
) +
geom_smooth(method = "lm", se = FALSE, linetype = "dashed") +
labs(x = "Hardship",
y = "Gender Effect") +
theme_minimal() +
xlim(-2, 2) +
coord_fixed(ratio = 6)